<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>转账记录</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style>
			.second_sty{
				/* border-top: 1px solid #e6e6e6; */
				padding-top: 20px;
				padding-bottom: 20px;
				margin-bottom: 20px;
			}
			.search_inline{
				margin-bottom: 20px;
			}
			.total_sty{
				width: 15%;
				text-align: center;
				padding: 15px 0;
				background-color: #f8f8f8;
			}
		</style>
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<!-- <div class="layui-card">
						<div class="layui-card-body">
							<div style="margin-bottom: 20px;">
								<button id="examine" class="layui-btn layui-btn-normal layui-btn-sm" >审核</button>
								<button id="importbill" class="layui-btn layui-btn-normal layui-btn-sm" data-type='importdata'>导入</button>
							</div>
							<ul class="layui-tab-title" style="margin-bottom: 20px">
							    <li class="layui-this" id="all_status">全部</li>
							    <li  id="examine_status">待审核</li>
							    <li  id="handle_status">待处理</li>
							    <li  id="finish_status">已完成</li>
							</ul>
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">时间段：</label>
									<div class="layui-input-inline" style="width: 200px;">
										<input class="layui-input" id="choosetime" placeholder="时间段" autocomplete="off">
										<input class="layui-input" type="text" id="startdate" name="startdate"
											placeholder="" autocomplete="off" style="display: none;">
										<input class="layui-input" type="text" id="enddate" name="enddate"
											placeholder="" autocomplete="off" style="display: none;">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">身份证号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="身份证号"
											name="cert_no" id="cert_no" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">店铺：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="店铺" name="shopid"
											id="shopid" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">姓名：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="姓名" name="card_name"
											id="card_name" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">用户编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="用户编号" name="user_id"
											id="user_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">银行卡号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="银行卡号" name="card_no"
											id="card_no" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">手机号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="手机号" name="mobile"
											id="mobile" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">提现编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="提现编号" name="cash_id"
											id="cash_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">分组：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="分组" name="groupname"
											id="groupname" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label" >审核状态：</label>
									<div class="layui-input-inline">
										<select name="audit_status" lay-verify="" id="audit_status">
											<option value="">全部</option>
											<option value="0">待审核</option>
											<option value="1">未通过</option>
											<option value="2">已通过</option>
										</select>
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search"
									data-type="reload" id="searchBtn">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
						</div>
					</div>
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="second_sty">
								<div class="total_sty">
									<div id="total_fee" style="font-size: 30px;">0</div>
									<h5 style="margin-top: 5px;">总金额</h5>
								</div>
							</div>
						</div>
					</div> -->
					<div class="layui-card">
						<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				// parent_id: getParam('id'),  
				btype: 1
			}

			
			var table_data=[]
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' ,//主入口模块
				excel: 'excel'
			}).use(['index', 'table', 'form', 'treeGrid','excel'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					treeGrid = layui.treeGrid,
					excel = layui.excel,
					admin = layui.admin;
				laydate.render({
					elem: '#choosetime',
					type: 'date',
					range: true,
					value: '',
					done: function(value, date) {
						$('input[name=startdate]').val(value.split(' - ')[0]);
						$('input[name=enddate]').val(value.split(' - ')[1]);
					}
				});
			$("#startdate").val(getstartime());
			$("#enddate").val(getenddate());	
			$("#choosetime").val(getstartime()+' - '+getenddate())
			if ($('#choosetime').val() !== '') {   // 判断 value 参数是否为空字符串
			  $("#startdate").val(getstartime());
			  $("#enddate").val(getenddate());
			  var _data = {
			    startdate: $("#startdate").val(),
			    enddate: $("#enddate").val(),
				status:$("#status").val(),
				cert_no:$("#cert_no").val(),
				shopid:$("#shopid").val(),
				card_name:$("#card_name").val(),
				user_id:$("#user_id").val(),
				card_no:$("#card_no").val(),
				mobile:$("#mobile").val(),
				cash_id:$("#cash_id").val(),
				groupname:$("#groupname").val(),
				audit_status:$("#audit_status").val(),
			  };
			}
			// getgrouping()
				initdata();

				function getstartime() {
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear + "-" + tMonth + "-" + tDate + "-00-00-00";
				}

				function getenddate() {
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear + "-" + tMonth + "-" + tDate + "-23-59-59";
				}

				function doHandleMonth(month) {
					var m = month;
					if (month.toString().length == 1) {
						m = "0" + month;
					}
					return m;
				}
				
				// tab 点击
				$('#all_status').click(()=>{
					_data.status=''
					initdata()
				})
				$('#examine_status').click(()=>{
					_data.status=0
					initdata()
				})
				$('#handle_status').click(()=>{
					_data.status=1
					initdata()
				})
				$('#finish_status').click(()=>{
					_data.status=2
					initdata()
				})

				function initdata() {
					// console.log(_data,'_data1111')
					table.render({
						elem: '#test-table-operate',
						id:'test',
						url: server.transfer_shop_transfer,
						// height: 'full-115',
						cellMinWidth: cellMinWidth,
						limit: limit,
						limits: limits,
						totalRow: true,
						cols: [
							[{type: 'checkbox', fixed: 'left'},
							    {
									width: 70,
									type: 'numbers',
									title: '序号',
									fixed: 'left',
								},
								// {
								// 	width: 170,
								// 	align: 'center',
								// 	fixed: 'right',
								// 	toolbar: '#test-table-operate-barDemo1',
								// 	title: '操作',
								// 	fixed: 'left'
								// },
								{
									field: 'shopid',
									title: '店铺编号',
									width: 100,
								}, {
									field: 'memberid',
									title: '操作人',
									width: 200,
								}, {
									field: 'out_memberid',
									width: 200,
									title: '出账会员'
								},
								{
									field: 'in_memberid',
									width: 150,
									title: '入账会员',
									sort: true
								},
								{
									field: 'out_accountic',
									width: 180,
									title: '出账账户'
								},

								{
									field: 'in_accoutid',
									width: 180,
									title: '入账账户',
									event: 'cert_no'
								},
								{
									field: 'trans_amt',
									width: 180,
									title: '交易金额',
									event: 'mobile'
								},
                                {
									field: 'fee_amt',
									width: 180,
									title: '手续费',
									event: 'cash_amt',
									totalRow: true
								},
								{
									field: 'notes',
									width: 180,
									title: '转账备注'
								},
								{
									field: 'old_amt',
									width: 100,
									title: '原账户金额'
								},
								{
									field: 'orderid',
									width: 250,
									title: '交易订单'
								},
								{
									field: 'extdata',
									width: 180,
									title: '扩展数据'
								},
								{
									field: 'add_by',
									title: '创建人',
									width: 200,
								}, {
									field: 'addtime',
									title: '创建时间',
									width: 200,
								}, {
									field: 'edit by',
									title: '更新人',
									width: 100,
								},{
									field: 'edittime',
									title: '更新时间',
									width: 200,
								}
							]
						],
						page: true,
						where: _data,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							console.log("这是数据", res);
							let shopdata = res.shop_cash_out.data
							table_data=res.shop_cash_out.data
							console.log(table_data,'table_data5555666')
							if(res.cashout_total){
								$('#total_fee').text(res.cashout_total.data.all_cash_amt)
							}else{
								$('#total_fee').text(0)
							}
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.shop_cash_out.pager.total, //解析数据长度
								"data": res.shop_cash_out.data //解析数据列表
							};
						}
					});
				}
				layui.use('table', function() {
				    var table = layui.table;
				    // 设置某一行为选中状态
				    function setRowSelected(rowId) {
				        table.setChecked('test', ["11de3af1ec1547c8bb1806935e5aa465"]); // 'test' 是表格的唯一 id，rowId 是行的唯一标识符
				    }
				  // 其他代码和表格初始化等...
				});

				//监听表格单击事件
				table.on('tool(test-table-operate)', function (obj) {
					console.log(obj)
					var key = obj.event
					if (!key) {
						return
					}
					var queryData = obj.data[key]
					$('input[name="' + key + '"]').val(queryData)
					$("#searchBtn").click()
				});
				
				$('#importbill').on('click', function() {
					var htmlContent = '<div style="width:100%;height:100%;text-align: center;">'
					htmlContent += '<div class="layui-upload-drag" id="importData" >';
					htmlContent += '<input multiple="multiple" type="file" style="cursor:pointer;opacity: 0.0; position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height:100%;">';
					htmlContent += '<i class="layui-icon"></i>';
					htmlContent += '<p id="filename">点击选择文件，或将文件拖拽到此处，支持多文件导入</p>';
					htmlContent += '</div>';
					htmlContent += '<div ">';
					//htmlContent += '<button id="downloadFiles" class="layui-btn" style="margin-top:10px;margin-bottom:10px;">下载模板</button>';
					htmlContent += '</div>';
					htmlContent += '</div>';
					layer.open({
						type: 1
						, offset: "auto"
						, id: 'layer_importData'
						, title: '导入'
						, area: '400px'
						, content: htmlContent    //需要打开的模板
						, btnAlign: 'c' //按钮居中
						, shade: 0 //不显示遮罩
						, success: function (layero, index) {
							// 监听上传文件的事件
							$('#importData').change(function (e) {
								var files = e.target.files;
								uploadExcel(files);
							});
							//下载模板
						}
		 
					});
				});

				$('#add').on('click', function() {
					layer.open({
						type: 2,
						title: '添加',
						shadeClose: true,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['750px', '700px'],
						content: 'model/edit_add.html?customerid=' + $("#customerid").val(),
						end: function() {

						}
					});
				});

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					console.log(data)
					let status_p=_data.status
					_data = data.field
					_data.status=status_p
					initdata();
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data = {}
					document.getElementById("form").reset();
					setTimeout(() => {
						$("#choosetime").val(getstartime() + ' - ' + getenddate())
						$("#startdate").val(getstartime())
						$("#enddate").val(getenddate())
						_data.startdate = $("#startdate").val()
						_data.enddate = $("#enddate").val()
						initdata();
					}, 100)
				});
				let ids=[]
				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					localStorage.removeItem('ids')
					if(obj.type=='all'){
						if(obj.checked){
							for(var i=0;i<table_data.length;i++){
								ids.push(table_data[i].id)
							}
						}else{
							ids=[]
						}
					}else if(obj.type=="one"){
						if(obj.checked){
							ids.push(obj.data.id)
						}else{
							for(var i=0;i<ids.length;i++){
								if(ids[i]==obj.data.id){
									ids.splice(i,1)
								}
							}
						}
					}
					ids=Array.from(new Set(ids))
					localStorage.setItem('ids',JSON.stringify(ids))
				});
				
				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'audit') {
						console.log(data)
						layer.open({
							type: 2,
							title: '审核',
							shadeClose: false,
							scrollbar: false,
							shade: 0.5,
							area: ['70%', '90%'],
							content: 'model/edit_add_audit.html?id=' + data.id,
						});
					}
				});
				$('#examine').click(()=>{
					
					layer.open({
						type: 2,
						title: '审核',
						shadeClose: false,
						scrollbar: false,
						shade: 0.5,
						area: ['40%', '60%'],
						content: 'model/edit_add_audit.html?id=',
					});
				})
   
				

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				
				function getgrouping(){
					$.post(server.sys_shop_cash_outcheckgroup_query,function(res,status){
						if(status == 'success'){
							if(res.code == 0){
								console.log(res,'ssssssss')
								if(res.groups){
									let datas=res.groups.data
									localStorage.setItem('groupList',JSON.stringify(datas))
								}else{
									let datas=[]
									localStorage.setItem('groupList',JSON.stringify(datas))
								}
								// layer.msg('登录成功',{time: 200},function(){
								// 	cookie.SetCookie('shop_token',res.system_token.data.token,365,domain,'/')
								// 	cookie.SetCookie('shop_uid',res.system_token.data.userid,365,domain,'/')
								// 	cookie.SetCookie('shop_roleid',res.member.data.role_id,365,domain,'/')
								// 	location = '../index.html'
								// });
							} else {
								// layer.msg(res.msg);
							}
							// closeloading();
						} else {
							layer.msg('服务器连接错误');
						}
					})
				}

				function getstartime() {
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear + "-" + tMonth + "-" + tDate;
				}

				function getenddate() {
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear + "-" + tMonth + "-" + tDate;
				}

				function doHandleMonth(month) {
					var m = month;
					if (month.toString().length == 1) {
						m = "0" + month;
					}
					return m;
				}
				
				function uploadExcel(files) {
				 
				        try {
							let filename = ''
							if(files.length>0){
								filename = files[0].name.replace('.xlsx','');
								
							}
							// for (let i = 0; i < files.length; i++) {
							// 	 files[i].name = files[i].name + 'test';
							// }
				            excel.importExcel(files, {
				                // 读取数据的同时梳理数据
				                fields: {
				                    'cash_id': 'A'//编号
									, 'card_no': 'B'//收款账户
									, 'card_name': 'C'//收款人名称
									, 'cert_no': 'D'//收款人身份证号
									, 'mobile': 'E'//收款人手机号
									, 'branch_name': 'F'//开户行支行名称
									, 'area_province': 'G'//收款人所在省
									, 'area_city': 'H'//收款人所在市
									, 'cash_amt': 'I'//金额
									, 'notes': 'J'//用途（附言）
									, 'user_id': 'K'//用户ID
									, 'dates': 'L'//申请时间
				                }
				            }, function (data) {
								alert(filename);
								let rows = data['0']['Sheet1'];
								let billdata = [];
								if(rows.length>0){
									for(let i =1;i<rows.length;i++){
										let row = rows[i];
										for(let p in row){
											row[p] = (''+row[p]).trim()
											if(p=='dates'){
												row[p] = row[p].substring(0,10)
											}
										}
										billdata.push(row);
									}
								}
								alert(JSON.stringify(billdata));
								
								if(billdata&&billdata.length){
									let _data = {
										groupname:filename
										,billdata:JSON.stringify(billdata)
									};
									$.post(server.sys_shop_cash_out_insert, _data, function(res, status) {
										console.log("看看提交的数据", server.sys_shop_cash_out_insert, _data);
										if (status == 'success') {
											if (res.code == 0) {
												console.log("修改成功后的", res);
												// layer.alert('操作成功', function() {
												// 	parent.layer.closeAll();
												// });
											} else {
												layer.msg(res.msg);
											}
											//closeloading();
										} else {
											//closeloading();
											layer.msg('服务器连接错误');
										}
									});
								}
								layer.closeAll();
				                // 还可以再进行数据梳理
				                /* data = excel.filterImportData(data, {
				                    'collection_point': 'A'
				                    , 'pass': 'B'
				                    , 'jump_out': 'C'
				                    , 'input': 'D'
				                */
				                //console.log("data", data, "files", files);
				 //                layer.open({
				 //                    title: '文件转换结果',
				 //                    area: ['60%', '90%'],
				 //                    btn: ['导入', '关闭'],
				 //                    content: laytpl($('#LAY-excel-export-ans').html()).render({ data: data, files: files }),
				 //                    success: function (data) {
				 //                    },
				 
				 //                    yes: function (index, layero) {
				 //                        var sLayer = layer.load();
				 //                        // 设置文件名
				 //                        // var filenames = "";
				 //                        // for(var i=0;i<files.length;i++){
				 //                        //     if(i===0){
				 //                        //         filenames += files[i].name;
				 //                        //     }else{
				 //                        //         filenames += "，"+files[i].name;
				 //                        //     }
				 //                        // }
				 //                        // $("#filename").text(filenames);
				 //                        var flag=true;
										
				 //                        //批量导入
				 //                        for (var key in data) {
				 //                            var import_data=data[key];
				 //                            // $.ajax({
				 //                            //     url: sessionStorage.getItem('httpUrlPrefix') + '/algorithm/process/execute',
				 //                            //     data:import_data,
				 //                            //     headers: { "Content-Type": "application/json;charset=utf-8" },
				 //                            //     async: false,
				 //                            //     type: 'post',
				 //                            //     success: function (result) {
				 //                            //         console.log("success", result);
				 //                            //     },
				 //                            //     error: function (result) {
				 //                            //         console.log("error", result);
				 //                            //         flag = false;
				 //                            //     }
				 //                            // });
				 //                        }
				 //                        layer.close(index);
				 //                        layer.close(index-1);
				 //                        layer.close(sLayer);
				 
				 //                        if(flag){
				 //                            layer.msg('导入成功！', { icon: 1 });
				 //                        }else{
				 //                            layer.msg('导入失败！', { icon: 2 });
				 //                        }
				 //                    },
				 //                    cancel: function (index, layero) {

				 //                    }
				 //                });
				            });
				        } catch (e) {
				            layer.alert(e.message);
				        }
					}
			});

			function seeimg(url) {
				//alert();
				var img_data = {
					"data": [{
						"src": url
					}]
				}
				layer.photos({
					photos: img_data,
					anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
				});
			}
		
		</script>
	</body>

</html>